import java.util.HashSet;
import java.util.Set;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User: Administrator
 * Data: 2023 - 07 - 27
 * Time: 9:28
 */
//力扣217.存在重复元素
public class Solution2 {
    //法一
    public boolean containsDuplicate1(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for(int x : nums) {
            if(!set.contains(x)) {
                set.add(x);
            }else {
                return true;
            }
        }
        return false;
    }
    //法二
    public boolean containsDuplicate2(int[] nums) {
        Set<Integer> set = new HashSet<Integer>();
        for (int x : nums) {
            if (!set.add(x)) {
                return true;
            }
        }
        return false;
    }
}
